package com.yanwq.simpleapplib.http.client;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

import java.io.IOException;

import okhttp3.Headers;
import okhttp3.Response;

/**
 * 作者：yanweiqiang。
 * 日期：2016/6/20 0020。
 */
public abstract class OkJsonObjectResponseCallback implements OkResponseCallback {

    @Override
    public void onSuccess(int status, Headers headers, Object obj) {
        onSuccess(status, headers, (JSONObject) obj);
    }

    @Override
    public JSONObject parse(Response response) {
        try {
            return JSON.parseObject(response.body().string());
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }

    public abstract void onSuccess(int status, Headers headers, JSONObject jsonObject);
}
